#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc2_r12_aux_h2o_sym_fop.info <<'%EOF%'
   cc2_r12_aux_h2o_sym_fop
   -------------
   Molecule:         H2O
   Wave Functions:   CC2-R12/A STO-3G 
   Test Purpose:     Check first order properties with symmetry
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > cc2_r12_aux_h2o_sym_fop.mol <<'%EOF%'
BASIS
STO-3G 3-21G
H2O:  CC2-R12/Ansatz1 dipole moment with symmetry

    4    2 X Z
 1      8.    1  
O     0.0 -0.2249058930 0.0
 1      1.    1 
H     1.45235 0.899623 0.0
 2      8.    1
O     0.0 -0.2249058930 0.0
 2      1.    1
H     1.45235 0.899623 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc2_r12_aux_h2o_sym_fop.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
.DIRECT
*MOLBAS
.R12AUX
**INTEGRALS
.R12
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT
.THRESHOLD
 1D-10
*ORBITALS
.MOSTART
 H1DIAG
*CC INPUT
.CC2
.PRINT
 3
.FREEZE
  1 0 
.THRENR
 1.0D-12
.THRLEQ
 1.0D-10
*CCFOP
.NONREL
.OPERAT
XDIPLEN
YDIPLEN
ZDIPLEN
*R12 INPUT
#.NO HYB
#.R12XXL
#.NO B
#.NO A'
#.NO 2
.CC2
 1A
.BASSCL 
 0.5 8.0
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc2_r12_aux_h2o_sym_fop.check
cat >>cc2_r12_aux_h2o_sym_fop.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi


#
#            Total SCF   energy:                   -74.9645140851
#            Total MP2-R12/A energy:               -75.3599268217
#            Total CC2-R12/A energy:               -75.3610583583
#
#                    XDIPLEN : zero by symmetry 
#                    YDIPLEN :  -0.71631508
#                    ZDIPLEN : zero by symmetry
#
CRIT1=`$GREP "Total MP2-R12/A energy: *-75.359926821" $log | wc -l`
TEST[1]=`expr   $CRIT1`
CTRL[1]=2
ERROR[1]="MP2-R12/A ENERGY NOT CORRECT"
CRIT2=`$GREP "Total CC2-R12/A energy: *-75.361058358" $log | wc -l`
TEST[2]=`expr   $CRIT2`
CTRL[2]=2
ERROR[2]="CC2-R12/A ENERGY NOT CORRECT"
#
CRIT3=`$GREP "YDIPLEN : * (-|-0)\.71631508" $log | wc -l`
TEST[3]=`expr   $CRIT3`
CTRL[3]=1
ERROR[3]="CC2-R12/A Y-DIPOLE MOMENT NOT CORRECT"

PASSED=1
for i in 1 2 3 
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
